<template>
  <div class="cus">
    <div class="cus_box">
      <div class="title"><span>修改密码</span> <i @click="$emit('changePwdCall')" class="el-icon-close"></i></div>
      <div class="content">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
          <el-form-item label="新密码" prop="password">
            <el-input v-model="dataForm.password" type="text" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item label="确认密码" prop="password2">
            <el-input v-model="dataForm.password2" type="text" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
        <div class="btns">
          <el-button @click="$emit('changePwdCall')">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {isMobile } from '@/utils/validate'
  export default {
    data () {
      var validateMobile = (rule, value, callback) => {
        if (!isMobile(value)) {
          callback(new Error('手机号格式错误'))
        } else {
          callback()
        }
      };
      var password2=(rule, value, callback)=>{
        console.log(value);
        console.log(this.dataForm.password);
        if (value!=this.dataForm.password) {
          callback(new Error('两次密码不一样'))
        } else {
          callback()
        }
      }
      return {
        dataForm: {
          password:'',
          password2:'',
        },
        dataRule: {
          password: [
            { required: true, message: '请输入', trigger: 'blur' },
          ],
          password2:[
            { required: true, message: '请输入', trigger: 'blur' },
            { validator: password2, trigger: 'blur' }
          ]
        }
      }
    },
    props:['res'],
    mounted(){

    },

    methods: {
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
              this.submit();
          }
        })
      },
      async submit(){
        var res=await this.apis.edit_user({
          id:this.res.id,
          password:this.dataForm.password
        });
        this.$emit('changePwdCall');
        this.$message({
          message:'操作成功',
          type:'success'
        });
      },


      areaChange(e){}
    }
  }
</script>
<style scoped lang='scss'>

</style>
